Ext.define('AM.data.XMLParser', {

    singleton:true,


    createPPTByName: function(name) {
        Ext.Ajax.request({
            url: 'ReadXML',
            params: {
                pptName: name
            },
            success: function(response) {
                var xml = response.responseXML;
                AM.data.XMLParser.createPPTByXML(xml);
            }
        })
    },


    createPPTByXML: function(xml) {
        var me = AM.data.XMLParser;
        var page_nodeArr = xml.getElementsByTagName('page');
        Ext.each(page_nodeArr, function (page_node) {
            var pageConfig = me._getCmpConfig(page_node);
            var cmps = [];
            var text_nodeArr = page_node.getElementsByTagName('text');
            Ext.each(text_nodeArr, function (cmp_node) {
                var cmpConfig = me._getCmpConfig(cmp_node);
                var cmp = Ext.create('AM.component.Text', null, cmpConfig);
                cmps.push(cmp);
            });
            var img_nodeArr = page_node.getElementsByTagName('_image');
            Ext.each(img_nodeArr, function (cmp_node) {
                var cmpConfig = me._getCmpConfig(cmp_node);
                var cmp = Ext.create('AM.component.Image', null, cmpConfig);
                cmps.push(cmp);
            });
            var audio_nodeArr = page_node.getElementsByTagName('audio');
            Ext.each(audio_nodeArr, function(audio_node){
                var cmpConfig = me._getCmpConfig(audio_node);
                var cmp = Ext.create('AM.component.Audio', null, cmpConfig);
                cmps.push(cmp);
            });

            Ext.create('AM.component.Page', {items:cmps}, pageConfig);
        });
    },

    _getCmpConfig:function (node) {
        var config = {};
        Ext.each(node.attributes, function (p) {
            config[p.name] = p.value;
        });
        return config;
    }


})